package com.hongdee.crm.saMessage.controller;

import com.hongdee.base.entity.ResultEntity;
import com.hongdee.crm.saMessage.entity.TCrmCarSaMessage;
import com.hongdee.crm.saMessage.service.ITCrmCarSaMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 名  称:TCrmCarSaMessageController
 * 类  型:class
 * 描  述:
 * 路  径:com.hongdee.crm.saMessage.controller
 * 作  者: 术洪超
 * 日  期:2017-03-21 17:03
 */
@RestController
@RequestMapping("/crm/saMessage")
public class TCrmCarSaMessageController {

    @Autowired
    private ITCrmCarSaMessageService itCrmCarSaMessageService;

    /**
     * @param uid   登录用户 ID
     * @param token 登录用户 token
     * @param start 起始记录
     * @param limit 页面大小
     * @return Map
     * @throws Exception
     * @desc 通过 JDBCDao分页查询
     * @author 术洪超
     */

    @RequestMapping("/page")
    @ResponseBody
    public Map page(@RequestParam(name = "uid", defaultValue = "") String uid,
                    @RequestParam(name = "token", defaultValue = "") String token,
                    @RequestParam(name = "start", defaultValue = "0") String start,
                    @RequestParam(name = "limit", defaultValue = "50") String limit
    ) throws Exception {

        Map map = itCrmCarSaMessageService.page(start, limit, uid);
        map.put("success", true);
        map.put("msg", "分页查询成功！");
        return map;
    }


    /**
     * @return Map
     * @throws Exception
     * @desc 保存添加或者修改的实体内容，通过主键判断
     * @author 术洪超
     */
    @RequestMapping("/saveOrder")
    @ResponseBody
    public ResultEntity saveOrder(@RequestParam(name = "uid", defaultValue = "") String uid,
                                  @RequestParam(name = "token", defaultValue = "") String token) throws Exception {
        TCrmCarSaMessage tm = this.itCrmCarSaMessageService.saveOrder(uid);
        ResultEntity res = new ResultEntity();
        res.setMsg("保存成功！");
        res.setSuccess(true);
        res.setData(tm);
        return res;
    }


    /**
     * @return Map
     * @throws Exception
     * @desc
     * @author 术洪超
     */
    @RequestMapping("/saveCar")
    @ResponseBody
    public ResultEntity saveCar(@RequestParam(name = "uid", defaultValue = "") String uid,
                                @RequestParam(name = "token", defaultValue = "") String token) throws Exception {
        TCrmCarSaMessage tm = this.itCrmCarSaMessageService.saveCar(uid);
        ResultEntity res = new ResultEntity();
        res.setMsg("保存成功！");
        res.setSuccess(true);
        res.setData(tm);
        return res;
    }


}
